<template>
  <LoginHeader>联合登录</LoginHeader>
  <section class="container">
    <nav class="tab">
      <a
        href="javascript:;"
        :class="{ active: isActive }"
        @click="isActive = true"
      >
        <i class="iconfont icon-bind" />
        <span>已有小兔鲜账号，请绑定手机</span>
      </a>
      <a
        href="javascript:;"
        :class="{ active: !isActive }"
        @click="isActive = false"
      >
        <i class="iconfont icon-edit" />
        <span>没有小兔鲜账号，请完善资料</span>
      </a>
    </nav>
    <div class="tab-content" v-if="isActive">
      <CallbackBind />
    </div>
    <div class="tab-content" v-else>
      <CallbackPatch />
    </div>
  </section>
  <LoginFooter />
</template>

<script>
import LoginHeader from './login-header'
import LoginFooter from './login-footer'
import CallbackBind from './callback-bind'
import CallbackPatch from './callback-patch'
import { ref, provide } from 'vue'
import QC from 'qc'
export default {
  name: 'PageCallback',
  components: { LoginHeader, LoginFooter, CallbackBind, CallbackPatch },
  setup () {
    // tab栏切换
    const isActive = ref(true)

    // 检查是否已经登录
    const res = QC.Login.check()

    // 用户信息
    const qqUserInfo = ref({})

    // openId：用户身份的唯一标识
    // accessToken：表示当前用户在此网站/应用的登录状态与授权信息
    QC.Login.getMe((openId, accessToken) => {
      qqUserInfo.value = { ...qqUserInfo.value, openId, accessToken }
    })

    // 获取用户信息
    if (res) {
      QC.api('get_user_info').success((user) => {
        qqUserInfo.value = { ...qqUserInfo.value, ...user.data }
      })
    }

    provide('qqUserInfo', qqUserInfo)

    return { isActive, qqUserInfo }
  }
}
</script>

<style scoped lang='less'>
.container {
  padding: 25px 0;
}
.tab {
  background: #fff;
  height: 80px;
  padding-top: 40px;
  font-size: 18px;
  text-align: center;
  a {
    color: #666;
    display: inline-block;
    width: 350px;
    line-height: 40px;
    border-bottom: 2px solid #e4e4e4;
    i {
      font-size: 22px;
      vertical-align: middle;
    }
    span {
      vertical-align: middle;
      margin-left: 4px;
    }
    &.active {
      color: @xtxColor;
      border-color: @xtxColor;
    }
  }
}
.tab-content {
  min-height: 600px;
  background: #fff;
}
</style>
